<cfsilent>
<!---
Copyright: (c) 2006 The MachBlog Authors
Authors: Matt Woodward (mpwoodward@gmail.com) & Peter J. Farrell (pjf@maestropublishing.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License.

$Id: blogEntryForm.cfm 947 2006-08-24 01:14:46Z mpwoodward $

Notes:
TODO: Figure out how to do validation with qforms against FCK
--->
</cfsilent>

<cfoutput>
<script type="text/javascript">
	<!--//--><![CDATA[//><!--
	function deleteEntry(entryId) {
		var msg = "#getProperty('resourceBundleService').getResourceBundle().getResource('deleteentryconfirm')#";
		if (confirm(msg)) {
			var url = "#BuildUrl('deleteBlogEntry', 'entryId=1')#";
			url = url.replace(/1/, entryId);
			location.replace(url);
		}
	}
	//--><!]]>
</script>

<h2>
	<cfif entry.getEntryId() EQ "">
		#getProperty("resourceBundleService").getResourceBundle().getResource("createblogentry")#
	<cfelse>
		#getProperty("resourceBundleService").getResourceBundle().getResource("updateblogentry")#
	</cfif>
</h2>

<cfif IsDefined("message")>
	<p style="color:red;">#variables.message#</p>
</cfif>

<form name="blogEntryForm" action="index.cfm?#getProperty('eventParameter')#=processBlogEntryForm" method="post" enctype="multipart/form-data">
	<table border="0" cellpadding="2" cellspacing="1" width="100%">
		<tr>
			<td>* #getProperty("resourceBundleService").getResourceBundle().getResource("title")#</td>
			<td>
				<input type="text" name="title" size="30" maxlength="100" 
						value="#variables.entry.getTitle()#" />
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<table border="0" cellpadding="2" cellspacing="1" width="100%">
					<tr>
						<td>* #getProperty("resourceBundleService").getResourceBundle().getResource("entry")#</td>
					</tr>
					<tr>
						<td>
							<cfif getProperty("useWysiwygEditor")>
								<cfswitch expression="#getProperty('wysiwygEditor')#">
									<cfcase value="FCKeditor">
										<cfset bodyEditor = CreateObject("component", "machblog.FCKeditor.fckeditor") />
										<cfset bodyEditor.instanceName = "body" />
										<cfset bodyEditor.value = "#variables.entry.getBody()#" />
										<cfset bodyEditor.basePath = "#getProperty('applicationRoot')#FCKeditor" />
										<cfset bodyEditor.width = "100%" />
										<cfset bodyEditor.height="300" />
										<cfset bodyEditor.create() />
									</cfcase>
									
									<cfdefaultcase>
										<em>#getProperty("resourceBundleService").getResourceBundle().getResource("wysiwygeditornotvalid")#</em>
									</cfdefaultcase>
								</cfswitch>
								<cfelse>
									<textarea name="body" cols="60" rows="10">#variables.entry.getBody()#</textarea>
							</cfif>
						</td>
					</tr>
					<tr>
						<td>#getProperty("resourceBundleService").getResourceBundle().getResource("extendedentry")#</td>
					</tr>
					<tr>
						<td>
							<cfif getProperty("useWysiwygEditor")>
								<cfswitch expression="#getProperty('wysiwygEditor')#">
									<cfcase value="fckEditor">
										<cfset moreBodyEditor = CreateObject("component", "machblog.FCKeditor.fckeditor") />
										<cfset moreBodyEditor.instanceName = "moreBody" />
										<cfset moreBodyEditor.value = "#variables.entry.getMoreBody()#" />
										<cfset moreBodyEditor.basePath = "#getProperty('applicationRoot')#FCKeditor" />
										<cfset moreBodyEditor.width = "100%" />
										<cfset moreBodyEditor.height="300" />
										<cfset moreBodyEditor.create() />
									</cfcase>
									
									<cfdefaultcase>
										<em>#getProperty("resourceBundleService").getResourceBundle().getResource("wysiwygeditornotvalid")#</em>
									</cfdefaultcase>
								</cfswitch>
								<cfelse>
									<textarea name="moreBody" cols="60" rows="10">#variables.entry.getMoreBody()#</textarea>
							</cfif>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td valign="top">#getProperty("resourceBundleService").getResourceBundle().getResource("category")#</td>
			<td valign="top">
				<select name="category" size="5" multiple="true">
					<cfloop query="categories">
						<option value="#category_id#"<cfif ListFind(variables.categoryIds, category_id, ",")> selected</cfif>>#category_name#</option>
					</cfloop>
				</select>
			</td>
		</tr>
		<tr>
			<td>#getProperty("resourceBundleService").getResourceBundle().getResource("newcategory")#</td>
			<td>
				<input type="text" name="newCategory" size="30" maxlength="50" />
			</td>
		</tr>
		<tr>
			<td valign="top">#getProperty("resourceBundleService").getResourceBundle().getResource("uploadphoto")#</td>
			<td valign="top">
				<input type="file" name="photo" size="30" />
				<cfif variables.entry.getPhoto() NEQ "">[<a href="javascript:void(0);" onclick="javascript:window.open('uploads/photos/#GetFileFromPath(variables.entry.getPhoto())#', 'photowindow', 'height=500,width=500,location=no,resizable=yes,status=no,toolbar=no');">#getProperty("resourceBundleService").getResourceBundle().getResource("currentphoto")#: #getFileFromPath(variables.entry.getPhoto())#</a>]</cfif><br />
				#getProperty("resourceBundleService").getResourceBundle().getResource("uploadphotonote")#<cfif variables.entry.getPhoto() NEQ ""><br />
				<input type="checkbox" name="deletePhoto" value="1" />#getProperty("resourceBundleService").getResourceBundle().getResource("deletephoto")#</cfif>
			</td>
		</tr>
		<tr>
			<td valign="top">#getProperty("resourceBundleService").getResourceBundle().getResource("enclosure")#</td>
			<td valign="top">
				<input type="file" name="enclosure" size="30" />
				<cfif variables.entry.getEnclosure() NEQ "">[<a href="javascript:void(0);" onclick="javascript:window.open('uploads/enclosures/#GetFileFromPath(variables.entry.getEnclosure())#', 'enclosurewindow', 'height=500,width=500,location=no,resizable=yes,status=no,toolbar=no');">#getProperty("resourceBundleService").getResourceBundle().getResource("currentenclosure")#: #getFileFromPath(variables.entry.getEnclosure())#</a>]</cfif><br />
				#getProperty("resourceBundleService").getResourceBundle().getResource("enclosurenote")#<cfif variables.entry.getEnclosure() NEQ ""><br />
				<input type="checkbox" name="deleteEnclosure" value="1" />#getProperty("resourceBundleService").getResourceBundle().getResource("deleteenclosure")#</cfif>
			</td>
		</tr>
		<tr>
			<td>* #getProperty("resourceBundleService").getResourceBundle().getResource("datetimetopost")#</td>
			<td>
				<input type="text" name="dtPosted" id="dtPosted" size="30" maxlength="30" 
						readonly="true" />
				<img src="js/calendar/calbutton.gif" id="calendarTrigger" 
						style="cursor: pointer;" />
			</td>
		</tr>
		<tr>
			<td>#getProperty("resourceBundleService").getResourceBundle().getResource("allowcomments")#</td>
			<td>
				<input type="checkbox" name="allowComments" value="1"<cfif variables.entry.getAllowComments() EQ 1> checked</cfif> />
			</td>
		</tr>
		<tr>
			<td>#getProperty("resourceBundleService").getResourceBundle().getResource("allowtrackbacks")#</td>
			<td>
				<input type="checkbox" name="allowTrackbacks" value="1"<cfif variables.entry.getAllowTrackbacks() EQ 1> checked</cfif> />
			</td>
		</tr>
		<tr>
			<td>#getProperty("resourceBundleService").getResourceBundle().getResource("makeactive")#</td>
			<td>
				<input type="checkbox" name="isActive" value="1"<cfif variables.entry.getAudit().getIsActive() EQ 1 OR variables.entry.getEntryId() EQ ""> checked</cfif> />
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<input type="submit" name="submit" 
						value="<cfif entry.getEntryId() EQ "">#getProperty('resourceBundleService').getResourceBundle().getResource('createblogentry')#<cfelse>#getProperty('resourceBundleService').getResourceBundle().getResource('updateblogentry')#</cfif>" />&nbsp;
				<cfif entry.getEntryId() NEQ "">
					<input type="button" name="delete" value="#getProperty('resourceBundleService').getResourceBundle().getResource('deleteentry')#" 
						onClick="javascript:deleteEntry('#entry.getEntryId()#');" />
				<cfelse>
					<input type="button" name="cancel" value="#getProperty('resourceBundleService').getResourceBundle().getResource('cancel')#" 
							onClick="javascript:history.back();" />
				</cfif>
			</td>
		</tr>
	</table>
	<input type="hidden" name="entryId" value="#entry.getEntryId()#" />
	<input type="hidden" name="oldPhoto" value="#GetFileFromPath(entry.getPhoto())#" />
	<input type="hidden" name="oldEnclosure" value="#GetFileFromPath(entry.getEnclosure())#" />
</form>

<!--- if this is an edit, show the comments and trackbacks --->
<cfif entry.getEntryId() NEQ "">
	<cfif comments.RecordCount GT 0>
		<form name="commentForm" action="index.cfm?#getProperty('eventParameter')#=deleteComments" method="post">
		<table border="0" width="100%" cellpadding="2" cellspacing="1">
			<tr>
				<td colspan="4"><h3>#getProperty("resourceBundleService").getResourceBundle().getResource("comments")#</h3></td>
			</tr>
			<tr bgcolor="##dedede">
				<td><strong>#getProperty("resourceBundleService").getResourceBundle().getResource("deletecap")#</strong></td>
				<td><strong>#getProperty("resourceBundleService").getResourceBundle().getResource("postedby")#</strong></td>
				<td><strong>#getProperty("resourceBundleService").getResourceBundle().getResource("dateposted")#</strong></td>
				<td><strong>#getProperty("resourceBundleService").getResourceBundle().getResource("comment")#</strong></td>
				<td><strong>#getProperty("resourceBundleService").getResourceBundle().getResource("actions")#</strong></td>
			</tr>
			<cfloop query="comments">
				<cfset rowBgColor = IIf(comments.CurrentRow MOD 2 EQ 0, DE("eeeeee"), DE("ffffff")) />
				<tr bgcolor="###rowBgColor#">
					<td align="center">
						<input type="checkbox" name="deleteIds" value="#comment_id#" />
					</td>
					<td>
						<cfif url NEQ "">
							<a href="#url#" target="_blank">#name#</a>
						<cfelse>
							#name#
						</cfif>
					</td>
					<td>
						#getProperty("resourceBundleService").getLocaleUtils().i18nDateTimeFormat(dt_created, 3, 3)#
					</td>
					<td>
						<a href="javascript:doPopup('index.cfm?#getProperty('eventParameter')#=showComments&entryId=#entry.getEntryId()#&commentId=#comment_id#', 500, 500, false)">
							#Left(comment, 15)#<cfif Len(comment) GT 15>...</cfif>
						</a>
					</td>
					<td>
						<cfif is_active>
							<a href="index.cfm?#getProperty('eventParameter')#=toggleCommentDisplay&commentId=#comment_id#&entryId=#entry.getEntryId()#&action=#getProperty('resourceBundleService').getResourceBundle().getResource('hide')#">
								#getProperty("resourceBundleService").getResourceBundle().getResource("hide")#
							</a>
						<cfelse>
							<a href="index.cfm?#getProperty('eventParameter')#=toggleCommentDisplay&commentId=#comment_id#&entryId=#entry.getEntryId()#&action=#getProperty('resourceBundleService').getResourceBundle().getResource('show')#">
								#getProperty("resourceBundleService").getResourceBundle().getResource("approve")#
							</a>
						</cfif> | 
						<cfif ip_is_blocked>
							<a href="index.cfm?#getProperty('eventParameter')#=toggleIpBlock&ipAddress=#ip_created#&action=#getProperty('resourceBundleService').getResourceBundle().getResource('unblock')#&entryId=#entry.getEntryId()#">
								#getProperty("resourceBundleService").getResourceBundle().getResource("unblockip")#
							</a>
						<cfelse>
							<a href="index.cfm?#getProperty('eventParameter')#=toggleIpBlock&ipAddress=#ip_created#&action=#getProperty('resourceBundleService').getResourceBundle().getResource('block')#&entryId=#entry.getEntryId()#">
								#getProperty("resourceBundleService").getResourceBundle().getResource("blockip")#
							</a>
						</cfif>
					</td>
				</tr>
			</cfloop>
			<tr>
				<td colspan="5" align="right">
					<input type="submit" name="delete" value="#getProperty('resourceBundleService').getResourceBundle().getResource('deletecomments')#" />
				</td>
			</tr>
		</table>
		<input type="hidden" name="entryId" value="#entry.getEntryId()#" />
		</form>
	</cfif>
	
	<cfif trackbacks.RecordCount GT 0>
		<cfdump var="#trackbacks#" />
	</cfif>
</cfif>

<script type="text/javascript">
	// calendar settings
	Calendar.setup(
		{
			inputField : "dtPosted", 
			ifFormat : "%m/%d/%Y %I:%M %P", 
			button : "calendarTrigger", 
			showsTime: true, 
			timeFormat: "12"
		}
	);
	
	// set default calendar value to current date/time
	var curDate = new Date();
	if (document.forms.blogEntryForm.entryId.value != '') {
		curDate = new Date(#getProperty("resourceBundleService").getLocaleUtils().getYear(entry.getDtPosted())#, 
									#getProperty("resourceBundleService").getLocaleUtils().getMonth(entry.getDtPosted()) - 1#, 
									#getProperty("resourceBundleService").getLocaleUtils().getDay(entry.getDtPosted())#, 
									#getProperty("resourceBundleService").getLocaleUtils().getHour(entry.getDtPosted())#, 
									#getProperty("resourceBundleService").getLocaleUtils().getMinute(entry.getDtPosted())#, 
									#getProperty("resourceBundleService").getLocaleUtils().getSecond(entry.getDtPosted())#);
	}
	document.getElementById("dtPosted").value = curDate.print("%m/%d/%Y %I:%M %P");
	
	// form validation
	objForm = new qForm("blogEntryForm");

	// set required fields and do additional validation
	objForm.title.required = true;
	objForm.title.validateNotEmpty();
	objForm.title.description = "#getProperty('resourceBundleService').getResourceBundle().getResource('title')#";
	//objForm.body.required = true;
	//objForm.body.validateNotEmpty();
	//objForm.body.description = "#getProperty('resourceBundleService').getResourceBundle().getResource('entry')#";
	//objForm.moreBody.required = false;
	//objForm.moreBody.description = "#getProperty('resourceBundleService').getResourceBundle().getResource('extendedentry')#";
	//objForm.moreBody.validateNotEmpty("#getProperty('resourceBundleService').getResourceBundle().getResource('extendedentryallspaces')#");
	objForm.dtPosted.required = true;
	objForm.dtPosted.description = "#getProperty('resourceBundleService').getResourceBundle().getResource('datetimetopost')#";
	
	// user needs to either choose a category or enter a new one
	objForm.newCategory.description = "#getProperty('resourceBundleService').getResourceBundle().getResource('category')#";
	objForm.newCategory.createDependencyTo("category", "this.getValue() == ''");
	objForm.category.enforceDependency();
</script>
</cfoutput>